package com.njbw.train.member.controller;

import com.njbw.train.common.resp.CommonResp;
import com.njbw.train.member.domain.MemberDomainService;
import com.njbw.train.member.entity.dto.MemberDto;
import com.njbw.train.member.entity.dto.MemberLoginDto;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Resource
    private MemberDomainService memberDomainService;

    @GetMapping("/count")
    public CommonResp<?> count() {
        return new CommonResp<>(memberDomainService.count());
    }

    @PostMapping("/register")
    public CommonResp<?> register(@RequestBody @Valid MemberDto memberDto) {
        return new CommonResp<>(memberDomainService.register(memberDto));
    }

    @PostMapping("/sendCode")
    public CommonResp<?> sendCode(@RequestBody @Valid MemberDto memberDto) {
        memberDomainService.sendCode(memberDto);
        return new CommonResp<>();
    }

    @PostMapping("/login")
    public CommonResp<?> login(@RequestBody @Valid MemberLoginDto memberLoginDto){
        return new CommonResp<>(memberDomainService.login(memberLoginDto));
    }
}
